using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VDWGMELD
    {
        public DataRow Convert2DWGMELD(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryDWGMELD(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["DWGMANDANT"] = " ".PadRight(2 ); 
         dwReturn["DWGMELDKR"] = " ".PadRight(2 ); 
         dwReturn["DWGMELDLFD"] = " ".PadRight(8 ); 
         dwReturn["DWGPROG"] = " ".PadRight(8 ); 
         dwReturn["DWGPRIO"] = " ".PadRight(1 ); 
         dwReturn["DWGSTA"] = " ".PadRight(2 ); 
         dwReturn["DWGKZWK"] = " ".PadRight(1 ); 
         dwReturn["DWGKW"] = " ".PadRight(2 ); 
         dwReturn["DWGKWJJ"] = " ".PadRight(4 ); 
         dwReturn["DWGTERMINV"] = " ".PadRight(8 ); 
         dwReturn["DWGTERMINB"] = " ".PadRight(8 ); 
         dwReturn["DWGGEBEARB"] = " ".PadRight(10 ); 
         dwReturn["DWGKONSMT"] = " ".PadRight(4 ); 
         dwReturn["DWGKONERLB"] = " ".PadRight(8 ); 
         dwReturn["DWGKONBEARB"] = " ".PadRight(10 ); 
         dwReturn["DWGKONIMT"] = " ".PadRight(4 ); 
         dwReturn["DWGKONERLA"] = " ".PadRight(8 ); 
         dwReturn["DWGSYSSMT"] = " ".PadRight(4 ); 
         dwReturn["DWGSYSERLB"] = " ".PadRight(8 ); 
         dwReturn["DWGSYSBEARB"] = " ".PadRight(10 ); 
         dwReturn["DWGSYSIMT"] = " ".PadRight(4 ); 
         dwReturn["DWGSYSERLA"] = " ".PadRight(8 ); 
         dwReturn["DWGPROSMT"] = " ".PadRight(4 ); 
         dwReturn["DWGPROERLB"] = " ".PadRight(8 ); 
         dwReturn["DWGPROBEARB"] = " ".PadRight(10 ); 
         dwReturn["DWGPROIMT"] = " ".PadRight(4 ); 
         dwReturn["DWGPROERLA"] = " ".PadRight(8 ); 
         dwReturn["DWGDOKSMT"] = " ".PadRight(4 ); 
         dwReturn["DWGDOKERLB"] = " ".PadRight(8 ); 
         dwReturn["DWGDOKBEARB"] = " ".PadRight(10 ); 
         dwReturn["DWGDOKIMT"] = " ".PadRight(4 ); 
         dwReturn["DWGDOKERLA"] = " ".PadRight(8 ); 
         dwReturn["DWGABNBEARB"] = " ".PadRight(10 ); 
         dwReturn["DWGABNERLA"] = " ".PadRight(8 ); 
         dwReturn["DWGAUSBEARB"] = " ".PadRight(10 ); 
         dwReturn["DWGAUSERLA"] = " ".PadRight(8 ); 
         dwReturn["DWGWMEDG"] = " ".PadRight(62 ); 
         dwReturn["DWGAENDG"] = " ".PadRight(1 ); 
         dwReturn["DWGAUSLG"] = " ".PadRight(1 ); 
         dwReturn["DWGKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["DWGAPNAME"] = " ".PadRight(20 ); 
         dwReturn["DWGAPTEL"] = " ".PadRight(20 ); 
         dwReturn["DWGSAGEB"] = " ".PadRight(20 ); 
         dwReturn["DWGSTADAT"] = " ".PadRight(8 ); 
         dwReturn["DWGGEDRUCKT"] = " ".PadRight(1 ); 
         dwReturn["DWGMEDAT"] = " ".PadRight(8 ); 
         dwReturn["DWGBEDAT"] = " ".PadRight(8 ); 
         dwReturn["DWGGALDAT"] = " ".PadRight(8 ); 
         dwReturn["DWGREFNR"] = " ".PadRight(10 ); 
         dwReturn["DWGAUFDAT"] = " ".PadRight(8 ); 
         dwReturn["DWGAUFMT"] = " ".PadRight(4 ); 
         dwReturn["DWGAUFDM"] = " ".PadRight(9 ); 
         dwReturn["DWGREDAT"] = " ".PadRight(8 ); 
         dwReturn["DWGRENR"] = " ".PadRight(10 ); 
         dwReturn["DWGALTENR"] = " ".PadRight(10 ); 
         dwReturn["DWGVERSION1"] = " ".PadRight(4 ); 
         dwReturn["DWGVERSION2"] = " ".PadRight(4 ); 
         dwReturn["DWGFILLER"] = " ".PadRight(20 ); 
         dwReturn["DWGAENDZL"] = " ".PadRight(0 ); 
         dwReturn["DWGAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["DWGAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["DWGNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["DWGNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapDWGMELD(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveDWGMELD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryDWGMELD(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapDWGMELD(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertDWGMELD(dwLocal, ITXDBVERSION);
            }
            UpdateDWGMELD(dwLocal);
        }
        public void InsertDWGMELD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO DWGMELD(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryDWGMELD(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM DWGMELD WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM DWGMELD  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "DWGMELD";
            Return = Result;
            return Return;
        }
        public void DeleteDWGMELD(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM DWGMELD   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateDWGMELD(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE DWGMELD SET "
                    +"DWGMANDANT= :DWGMANDANT,"
                    +"DWGMELDKR= :DWGMELDKR,"
                    +"DWGMELDLFD= :DWGMELDLFD,"
                    +"DWGPROG= :DWGPROG,"
                    +"DWGPRIO= :DWGPRIO,"
                    +"DWGSTA= :DWGSTA,"
                    +"DWGKZWK= :DWGKZWK,"
                    +"DWGKW= :DWGKW,"
                    +"DWGKWJJ= :DWGKWJJ,"
                    +"DWGTERMINV= :DWGTERMINV,"
                    +"DWGTERMINB= :DWGTERMINB,"
                    +"DWGGEBEARB= :DWGGEBEARB,"
                    +"DWGKONSMT= :DWGKONSMT,"
                    +"DWGKONERLB= :DWGKONERLB,"
                    +"DWGKONBEARB= :DWGKONBEARB,"
                    +"DWGKONIMT= :DWGKONIMT,"
                    +"DWGKONERLA= :DWGKONERLA,"
                    +"DWGSYSSMT= :DWGSYSSMT,"
                    +"DWGSYSERLB= :DWGSYSERLB,"
                    +"DWGSYSBEARB= :DWGSYSBEARB,"
                    +"DWGSYSIMT= :DWGSYSIMT,"
                    +"DWGSYSERLA= :DWGSYSERLA,"
                    +"DWGPROSMT= :DWGPROSMT,"
                    +"DWGPROERLB= :DWGPROERLB,"
                    +"DWGPROBEARB= :DWGPROBEARB,"
                    +"DWGPROIMT= :DWGPROIMT,"
                    +"DWGPROERLA= :DWGPROERLA,"
                    +"DWGDOKSMT= :DWGDOKSMT,"
                    +"DWGDOKERLB= :DWGDOKERLB,"
                    +"DWGDOKBEARB= :DWGDOKBEARB,"
                    +"DWGDOKIMT= :DWGDOKIMT,"
                    +"DWGDOKERLA= :DWGDOKERLA,"
                    +"DWGABNBEARB= :DWGABNBEARB,"
                    +"DWGABNERLA= :DWGABNERLA,"
                    +"DWGAUSBEARB= :DWGAUSBEARB,"
                    +"DWGAUSERLA= :DWGAUSERLA,"
                    +"DWGWMEDG= :DWGWMEDG,"
                    +"DWGAENDG= :DWGAENDG,"
                    +"DWGAUSLG= :DWGAUSLG,"
                    +"DWGKUNDNR= :DWGKUNDNR,"
                    +"DWGAPNAME= :DWGAPNAME,"
                    +"DWGAPTEL= :DWGAPTEL,"
                    +"DWGSAGEB= :DWGSAGEB,"
                    +"DWGSTADAT= :DWGSTADAT,"
                    +"DWGGEDRUCKT= :DWGGEDRUCKT,"
                    +"DWGMEDAT= :DWGMEDAT,"
                    +"DWGBEDAT= :DWGBEDAT,"
                    +"DWGGALDAT= :DWGGALDAT,"
                    +"DWGREFNR= :DWGREFNR,"
                    +"DWGAUFDAT= :DWGAUFDAT,"
                    +"DWGAUFMT= :DWGAUFMT,"
                    +"DWGAUFDM= :DWGAUFDM,"
                    +"DWGREDAT= :DWGREDAT,"
                    +"DWGRENR= :DWGRENR,"
                    +"DWGALTENR= :DWGALTENR,"
                    +"DWGVERSION1= :DWGVERSION1,"
                    +"DWGVERSION2= :DWGVERSION2,"
                    +"DWGFILLER= :DWGFILLER,"
                    +"DWGAENDZL= :DWGAENDZL,"
                    +"DWGAENDBEN= :DWGAENDBEN,"
                    +"DWGAENDDAT= :DWGAENDDAT,"
                    +"DWGNEUBEN= :DWGNEUBEN,"
                    +"DWGNEUDAT= :DWGNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("DWGMANDANT", OracleType.NVarChar).Value = dwData["DWGMANDANT"].ToString(); 
          or1.Parameters.Add("DWGMELDKR", OracleType.NVarChar).Value = dwData["DWGMELDKR"].ToString(); 
          or1.Parameters.Add("DWGMELDLFD", OracleType.NVarChar).Value = dwData["DWGMELDLFD"].ToString(); 
          or1.Parameters.Add("DWGPROG", OracleType.NVarChar).Value = dwData["DWGPROG"].ToString(); 
          or1.Parameters.Add("DWGPRIO", OracleType.NVarChar).Value = dwData["DWGPRIO"].ToString(); 
          or1.Parameters.Add("DWGSTA", OracleType.NVarChar).Value = dwData["DWGSTA"].ToString(); 
          or1.Parameters.Add("DWGKZWK", OracleType.NVarChar).Value = dwData["DWGKZWK"].ToString(); 
          or1.Parameters.Add("DWGKW", OracleType.NVarChar).Value = dwData["DWGKW"].ToString(); 
          or1.Parameters.Add("DWGKWJJ", OracleType.NVarChar).Value = dwData["DWGKWJJ"].ToString(); 
          or1.Parameters.Add("DWGTERMINV", OracleType.NVarChar).Value = dwData["DWGTERMINV"].ToString(); 
          or1.Parameters.Add("DWGTERMINB", OracleType.NVarChar).Value = dwData["DWGTERMINB"].ToString(); 
          or1.Parameters.Add("DWGGEBEARB", OracleType.NVarChar).Value = dwData["DWGGEBEARB"].ToString(); 
          or1.Parameters.Add("DWGKONSMT", OracleType.NVarChar).Value = dwData["DWGKONSMT"].ToString(); 
          or1.Parameters.Add("DWGKONERLB", OracleType.NVarChar).Value = dwData["DWGKONERLB"].ToString(); 
          or1.Parameters.Add("DWGKONBEARB", OracleType.NVarChar).Value = dwData["DWGKONBEARB"].ToString(); 
          or1.Parameters.Add("DWGKONIMT", OracleType.NVarChar).Value = dwData["DWGKONIMT"].ToString(); 
          or1.Parameters.Add("DWGKONERLA", OracleType.NVarChar).Value = dwData["DWGKONERLA"].ToString(); 
          or1.Parameters.Add("DWGSYSSMT", OracleType.NVarChar).Value = dwData["DWGSYSSMT"].ToString(); 
          or1.Parameters.Add("DWGSYSERLB", OracleType.NVarChar).Value = dwData["DWGSYSERLB"].ToString(); 
          or1.Parameters.Add("DWGSYSBEARB", OracleType.NVarChar).Value = dwData["DWGSYSBEARB"].ToString(); 
          or1.Parameters.Add("DWGSYSIMT", OracleType.NVarChar).Value = dwData["DWGSYSIMT"].ToString(); 
          or1.Parameters.Add("DWGSYSERLA", OracleType.NVarChar).Value = dwData["DWGSYSERLA"].ToString(); 
          or1.Parameters.Add("DWGPROSMT", OracleType.NVarChar).Value = dwData["DWGPROSMT"].ToString(); 
          or1.Parameters.Add("DWGPROERLB", OracleType.NVarChar).Value = dwData["DWGPROERLB"].ToString(); 
          or1.Parameters.Add("DWGPROBEARB", OracleType.NVarChar).Value = dwData["DWGPROBEARB"].ToString(); 
          or1.Parameters.Add("DWGPROIMT", OracleType.NVarChar).Value = dwData["DWGPROIMT"].ToString(); 
          or1.Parameters.Add("DWGPROERLA", OracleType.NVarChar).Value = dwData["DWGPROERLA"].ToString(); 
          or1.Parameters.Add("DWGDOKSMT", OracleType.NVarChar).Value = dwData["DWGDOKSMT"].ToString(); 
          or1.Parameters.Add("DWGDOKERLB", OracleType.NVarChar).Value = dwData["DWGDOKERLB"].ToString(); 
          or1.Parameters.Add("DWGDOKBEARB", OracleType.NVarChar).Value = dwData["DWGDOKBEARB"].ToString(); 
          or1.Parameters.Add("DWGDOKIMT", OracleType.NVarChar).Value = dwData["DWGDOKIMT"].ToString(); 
          or1.Parameters.Add("DWGDOKERLA", OracleType.NVarChar).Value = dwData["DWGDOKERLA"].ToString(); 
          or1.Parameters.Add("DWGABNBEARB", OracleType.NVarChar).Value = dwData["DWGABNBEARB"].ToString(); 
          or1.Parameters.Add("DWGABNERLA", OracleType.NVarChar).Value = dwData["DWGABNERLA"].ToString(); 
          or1.Parameters.Add("DWGAUSBEARB", OracleType.NVarChar).Value = dwData["DWGAUSBEARB"].ToString(); 
          or1.Parameters.Add("DWGAUSERLA", OracleType.NVarChar).Value = dwData["DWGAUSERLA"].ToString(); 
          or1.Parameters.Add("DWGWMEDG", OracleType.NVarChar).Value = dwData["DWGWMEDG"].ToString(); 
          or1.Parameters.Add("DWGAENDG", OracleType.NVarChar).Value = dwData["DWGAENDG"].ToString(); 
          or1.Parameters.Add("DWGAUSLG", OracleType.NVarChar).Value = dwData["DWGAUSLG"].ToString(); 
          or1.Parameters.Add("DWGKUNDNR", OracleType.NVarChar).Value = dwData["DWGKUNDNR"].ToString(); 
          or1.Parameters.Add("DWGAPNAME", OracleType.NVarChar).Value = dwData["DWGAPNAME"].ToString(); 
          or1.Parameters.Add("DWGAPTEL", OracleType.NVarChar).Value = dwData["DWGAPTEL"].ToString(); 
          or1.Parameters.Add("DWGSAGEB", OracleType.NVarChar).Value = dwData["DWGSAGEB"].ToString(); 
          or1.Parameters.Add("DWGSTADAT", OracleType.NVarChar).Value = dwData["DWGSTADAT"].ToString(); 
          or1.Parameters.Add("DWGGEDRUCKT", OracleType.NVarChar).Value = dwData["DWGGEDRUCKT"].ToString(); 
          or1.Parameters.Add("DWGMEDAT", OracleType.NVarChar).Value = dwData["DWGMEDAT"].ToString(); 
          or1.Parameters.Add("DWGBEDAT", OracleType.NVarChar).Value = dwData["DWGBEDAT"].ToString(); 
          or1.Parameters.Add("DWGGALDAT", OracleType.NVarChar).Value = dwData["DWGGALDAT"].ToString(); 
          or1.Parameters.Add("DWGREFNR", OracleType.NVarChar).Value = dwData["DWGREFNR"].ToString(); 
          or1.Parameters.Add("DWGAUFDAT", OracleType.NVarChar).Value = dwData["DWGAUFDAT"].ToString(); 
          or1.Parameters.Add("DWGAUFMT", OracleType.NVarChar).Value = dwData["DWGAUFMT"].ToString(); 
          or1.Parameters.Add("DWGAUFDM", OracleType.NVarChar).Value = dwData["DWGAUFDM"].ToString(); 
          or1.Parameters.Add("DWGREDAT", OracleType.NVarChar).Value = dwData["DWGREDAT"].ToString(); 
          or1.Parameters.Add("DWGRENR", OracleType.NVarChar).Value = dwData["DWGRENR"].ToString(); 
          or1.Parameters.Add("DWGALTENR", OracleType.NVarChar).Value = dwData["DWGALTENR"].ToString(); 
          or1.Parameters.Add("DWGVERSION1", OracleType.NVarChar).Value = dwData["DWGVERSION1"].ToString(); 
          or1.Parameters.Add("DWGVERSION2", OracleType.NVarChar).Value = dwData["DWGVERSION2"].ToString(); 
          or1.Parameters.Add("DWGFILLER", OracleType.NVarChar).Value = dwData["DWGFILLER"].ToString(); 
          or1.Parameters.Add("DWGAENDZL", OracleType.NVarChar).Value = dwData["DWGAENDZL"].ToString(); 
          or1.Parameters.Add("DWGAENDBEN", OracleType.NVarChar).Value = dwData["DWGAENDBEN"].ToString(); 
          or1.Parameters.Add("DWGAENDDAT", OracleType.NVarChar).Value = dwData["DWGAENDDAT"].ToString(); 
          or1.Parameters.Add("DWGNEUBEN", OracleType.NVarChar).Value = dwData["DWGNEUBEN"].ToString(); 
          or1.Parameters.Add("DWGNEUDAT", OracleType.NVarChar).Value = dwData["DWGNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
